/**
 * 郭楠project
 * com.gn.dao
 * ArticleDaoImpl.java
 * 创建人:TonyGuo 
 * 时间：2016年12月1日-下午11:40:31 
 * 2016Tm公司-版权所有
 */
package com.gn.mongo.dao;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.domain.Sort.Order;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import com.gn.commons.BaseMongo;
import com.gn.entity.Article;
import com.gn.util.CommonUtils;
import com.taoxeo.commons.lang.IdUtils;

/**
 * 
 * ArticleDaoImpl
 * 创建人:TonyGuo
 * 时间：2016年12月1日-下午11:40:31 
 * @version 1.0.0
 * 
 */
@Repository
public class ArticleDaoImpl extends BaseMongo<Article, String> implements ArticleDao {
	private static Logger logger = LoggerFactory.getLogger(ArticleDaoImpl.class);
	@Resource
	MongoTemplate mongoTemplate;

	public void save(Article article){
		article.setId(IdUtils.uuid());
		article.setCreatetime(CommonUtils.date2Str(new Date()));
		article.setState("no-reply");
		logger.info("【article==：{}】",article.toString());
		mongoTemplate.save(article);
	}
	
	@Override
	public List<Article> findRecommend() {
		return null;
	}
	
	@Override
	public List<Article> findArticleList() {
		Query query = new Query();
		Order order = new Order(Direction.DESC, Article.CREATETIME);
		query.with(new Sort(order));
		return find(query);
	}
	
	/*@Override
	public List<Article> findRecommend() {
		Query query = Query.query(Criteria.where(Article.PROP_RECOMMEND).is(true));
		Order order = new Order(Direction.DESC, Article.PROP_RECOMMEND_TIME);
		query.limit(SELECT_RECOMMEND_LIMIT);
		query.with(new Sort(order));
		query.fields().include(Article.PROP_ID)
		.include(Article.PROP_PICTURE)
		.include(Article.PROP_TITLE);
		
		return find(query);
	}
*/
	/**
	 * 【查找手术列表，如果为空，添加默认项目】
	 */
	/**public List<ContactOperation> findContactOperationListBy(String contactId){
		List<ContactOperation> contactOperations = getMongoSupport()
				.find(new Query(Criteria.where(ContactOperation.PROP_CID).is(contactId)).with(new Sort("oid")),entityClass);
		if(contactOperations.size()!=0){
			return contactOperations;
		}
		String defaultItem = "1";//如果手术列表为空，默认添加手术项（第一项）
		ContactOperation co = new ContactOperation();
		co.setContactId(contactId);
		co.setOid(defaultItem);
		co.setPastHistoryName("");
		co.setPastHistoryTime("");
		//co.setOperationName("");
		//co.setOperationDate("");
		getMongoSupport().insert(co, "contact_operation");
		List<ContactOperation> cos = new ArrayList<ContactOperation>();
		cos.add(co);
		return cos;
		
	}*/
	
	
	
	@Override
	public long count() {
		return count(new Query());
	}
	
	
	


}
